package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.activity.me.SettingActivity;
import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.AccountBean;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.NewCheckJoinMemberBean;
import com.mz.ozy.bean.NewResponeBean;
import com.mz.ozy.bean.UnreadMsgBean;
import com.mz.ozy.mvp.model.MeModel;
import com.mz.ozy.mvp.view.MeContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class MePresenter extends BasePresenterImpl<MeContract.View> implements MeContract.Presenter {

    private MeModel mModel;


    public MePresenter() {
        mModel = new MeModel();
    }

    @Override
    public void getMeInfo(Activity activity, boolean isShow) {
        mModel.getMeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView, isShow) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getgetMeInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void upAccountHeader(Context context) {
        mModel.getAccountInfo(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<AccountBean>(mView) {
                    @Override
                    public void onSuccesss(AccountBean bean) {
                        mView.getAccountSuccess(bean);
                    }
                });
    }

    @Override
    public void uploadHeader(Context context, String headPortrait, String nick) {
        mModel.uploadHeader(context, headPortrait, nick)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.uploadHeaderSuccess(bean);
                    }
                });
    }

    @Override
    public void getxi(Context context, String key) {
        mModel.getXy(context, key)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getxySuccess(bean);
                    }
                });
    }

    @Override
    public void getAli(Context context) {
        mModel.getALiInfo(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getAliSuccess(bean);
                    }
                });
    }

    @Override
    public void getBIndInfo(Context context, String type, String id) {
        mModel.getBindInfo(context, type, id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.bindInfo(type, bean);
                    }
                });
    }

    public void exitLogin(Context context) {
        mModel.exitLogin(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.exitLoginSuccess(bean);
                    }
                });
    }

    @Override
    public void onCancelBind(Context context, int type) {
        mModel.onCancelBind(context, type)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onCancelBindSuccess();
                    }
                });
    }

    @Override
    public void getUnreadMsg(Context context) {
        mModel.getUnreadMsg(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<UnreadMsgBean>(mView) {
                    @Override
                    public void onSuccesss(UnreadMsgBean bean) {
                        mView.getUnreadMsgSuccess(bean);
                    }
                });
    }
}
